{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-07T12:37:50.586721Z",
     "start_time": "2025-09-07T12:37:50.580383Z"
    }
   },
   "source": "from collections import namedtuple",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T12:37:51.269142Z",
     "start_time": "2025-09-07T12:37:51.265996Z"
    }
   },
   "cell_type": "code",
   "source": "myname = namedtuple(\"Person\", \"name, age, weight\")",
   "id": "d9c534cc37a52ac9",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T12:37:51.785481Z",
     "start_time": "2025-09-07T12:37:51.783635Z"
    }
   },
   "cell_type": "code",
   "source": "myname.name = \"李华\"",
   "id": "28e8df73f357dfea",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T12:37:52.300653Z",
     "start_time": "2025-09-07T12:37:52.297219Z"
    }
   },
   "cell_type": "code",
   "source": [
    "myname.age = 21\n",
    "myname.weight = 25\n",
    "print(myname.name, myname.age, myname.weight)"
   ],
   "id": "923a12d004847594",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "李华 21 25\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T12:37:52.823107Z",
     "start_time": "2025-09-07T12:37:52.821682Z"
    }
   },
   "cell_type": "code",
   "source": "import csv",
   "id": "41c5e45dee243de5",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T12:40:13.322459Z",
     "start_time": "2025-09-07T12:40:13.319353Z"
    }
   },
   "cell_type": "code",
   "source": "Person = namedtuple(\"Person\", \"name, age, weight\")",
   "id": "5910a36f736d54b7",
   "outputs": [],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T12:40:14.938359Z",
     "start_time": "2025-09-07T12:40:14.934002Z"
    }
   },
   "cell_type": "code",
   "source": [
    "for person in map(Person._make, csv.reader(open('./tuple.csv', 'r'))):\n",
    "    print(person.name, person.age, person.weight)"
   ],
   "id": "1d5350054be0ceb8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name age weight\n",
      "lihua 20 30\n",
      "张三 25 90\n",
      "zhaosi 30 120\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "e41b03317e6fef3b"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
